package com.sjt.ThreadDemo;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

@Slf4j
public class test {
    static int count=1000000;

    static int INT_MAX=Integer.MAX_VALUE;

    static int[]arr=new int[count];

    static int start=0,end=count-1;


    public static void main(String[] args)  {

               ThreadPool threadPool=new ThreadPool( 10,10);

               CountDownLatch countDownLatch=new CountDownLatch(1000000);

                long startTime=System.currentTimeMillis();

                for(int j=start;j<end;j++)
                {
                    int k = j;
                    threadPool.execute(new Runnable() {
                        @Override
                        public void run() {
                            arr[k]= k;
                        }
                    });
                    countDownLatch.countDown();
                }
                for(int j=end;j>start;j--)
                {
                    int k = j;
                    threadPool.execute(new Runnable() {
                        @Override
                        public void run() {
                            arr[k]=INT_MAX/ k;
                        }
                    });
                    countDownLatch.countDown();
                }

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long endTime = System.currentTimeMillis();
                System.out.println(endTime-startTime+"ms");


    }
}
